/////////////////////////////////////////////////////////////////////////////
// Name:        statusbarMetre.cpp
// Purpose:     
// Author:      Stephen Whittle
// Modified by: 
// Created:     09/08/2009 00:31:54
// RCS-ID:      
// Copyright:   
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes
#include <wx/dcbuffer.h>
#include "statusbarmetre.h"

////@begin XPM images
////@end XPM images


/*
 * statusBarMetre type definition
 */

IMPLEMENT_DYNAMIC_CLASS( statusBarMetre, wxWindow )


/*
 * statusBarMetre event table definition
 */

BEGIN_EVENT_TABLE( statusBarMetre, wxWindow )

////@begin statusBarMetre event table entries
    EVT_PAINT( statusBarMetre::OnPaint )

////@end statusBarMetre event table entries

END_EVENT_TABLE()


/*
 * statusBarMetre constructors
 */

statusBarMetre::statusBarMetre()
{
    Init();
}

statusBarMetre::statusBarMetre(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
    Init();
    Create(parent, id, pos, size, style);
}


/*
 * statusBarMetre creator
 */

bool statusBarMetre::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
{
////@begin statusBarMetre creation
    wxWindow::Create(parent, id, pos, size, style);
    CreateControls();
////@end statusBarMetre creation
maxValue = 400;
currentValue = 35;
    return true;
}


/*
 * statusBarMetre destructor
 */

statusBarMetre::~statusBarMetre()
{
////@begin statusBarMetre destruction
////@end statusBarMetre destruction
}


/*
 * Member initialisation
 */

void statusBarMetre::Init()
{
////@begin statusBarMetre member initialisation
////@end statusBarMetre member initialisation
}


/*
 * Control creation for statusBarMetre
 */

void statusBarMetre::CreateControls()
{    
////@begin statusBarMetre content construction
////@end statusBarMetre content construction
}


/*
 * Should we show tooltips?
 */

bool statusBarMetre::ShowToolTips()
{
    return true;
}

/*
 * Get bitmap resources
 */

wxBitmap statusBarMetre::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin statusBarMetre bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end statusBarMetre bitmap retrieval
}

/*
 * Get icon resources
 */

wxIcon statusBarMetre::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin statusBarMetre icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end statusBarMetre icon retrieval
}


/*
 * wxEVT_PAINT event handler for ID_PANEL
 */

void statusBarMetre::OnPaint( wxPaintEvent& event )
{
wxColourDatabase* ColourDB = new wxColourDatabase();
wxPaintDC statusDC(this);
wxSize statusSize = GetClientSize();
float percent = (currentValue/maxValue)*100;
if (percent >50){
statusDC.SetPen(*wxGREEN_PEN);
statusDC.SetBrush(*wxGREEN_BRUSH);
}else if (percent >25){
statusDC.SetPen(wxPen(ColourDB->Find(wxT("YELLOW"))));
statusDC.SetBrush(wxBrush(ColourDB->Find(wxT("YELLOW"))));

}else{
statusDC.SetPen(*wxRED_PEN);
statusDC.SetBrush(*wxRED_BRUSH);

}
//wxMessageBox(wxString::Format(wxT("%f"),(currentValue/maxValue)));
statusDC.DrawRectangle(0,0,((currentValue/maxValue) * statusSize.GetWidth()),statusSize.GetHeight());
statusDC.SetFont(wxFont(8, wxSWISS, wxNORMAL, wxNORMAL, false));
statusDC.DrawLabel(wxString::Format(wxT("%g"),currentValue) + wxT("/")+ wxString::Format(wxT("%g"),maxValue), wxRect(statusSize), wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL);
//
}

